package com.huarui.permission.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.ewaf.framework.action.BaseAction;

import com.huarui.permission.dataobject.Permission;
import com.huarui.permission.service.impl.PermissionManagerService;
import com.huarui.roleTemplate.service.RoleTemplateService;
import com.opensymphony.xwork2.Action;

public class PermissionAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private RoleTemplateService roleTemplateService;
	
	@SuppressWarnings("unchecked")
	private List list;
	private PermissionManagerService permissionManagerService;
	private String permissionJson;
	private Integer id;
	private Integer oldParentId;
	private Integer newParentId;
	private Map<String,Object> resultMap=new HashMap<String, Object>();
	public String getPermissionList(){
		list=roleTemplateService.getNoCheckPermissionList();
		return "list";
	}
	
	public String save(){
		Permission permission=(Permission) JSONObject.toBean(JSONObject.fromObject(permissionJson),Permission.class);
		resultMap=permissionManagerService.save(permission);
		return Action.SUCCESS;
	}
	
	public String delete(){
		resultMap=permissionManagerService.delete(id);
		return Action.SUCCESS;
	}
	public String updateParent(){
		resultMap=permissionManagerService.updateParent(id, oldParentId, newParentId);
		return Action.SUCCESS;
	}

	public RoleTemplateService getRoleTemplateService() {
		return roleTemplateService;
	}

	public void setRoleTemplateService(RoleTemplateService roleTemplateService) {
		this.roleTemplateService = roleTemplateService;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setPermissionManagerService(
			PermissionManagerService permissionManagerService) {
		this.permissionManagerService = permissionManagerService;
	}

	public void setPermissionJson(String permissionJson) {
		this.permissionJson = permissionJson;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setOldParentId(Integer oldParentId) {
		this.oldParentId = oldParentId;
	}

	public void setNewParentId(Integer newParentId) {
		this.newParentId = newParentId;
	}

	
}
